﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;


// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237

namespace QuizHackathon
{
    /// <summary>
    /// A basic page that provides characteristics common to most applications.
    /// </summary>
    public sealed partial class EngHard : QuizHackathon.Common.LayoutAwarePage
    {
        string[] questions;
        string[] answers;
        Random r;
        int x;
        int totalQuestions;
        public EngHard()
        {
            this.InitializeComponent();
            App myApp = (App)App.Current;
            questions = myApp.difficultEnglishQuestions;
            answers = myApp.difficultEnglishAnswers;
            r = new Random();
            x = r.Next() % 5;
            TextBlock_question.Text = questions[x];
            textbox_answer.Text = "";
            totalQuestions = 1;
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void textbox_answer_TextChanged(object sender, TextChangedEventArgs e)
        {
            
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (textbox_answer.Text.ToLower() == answers[x].ToLower())
            {
                Windows.UI.Popups.MessageDialog y = new Windows.UI.Popups.MessageDialog("Correct Answer! Bingo!");
                y.ShowAsync();
            }
            else
            {
                Windows.UI.Popups.MessageDialog y = new Windows.UI.Popups.MessageDialog("Sorry! Wrong Answer");
                y.ShowAsync();
            }
            if (totalQuestions < 5)
            {
                totalQuestions++;
                myFunc();
            }
            if (totalQuestions == 5)
            {
                this.Frame.Navigate(typeof(ResultAnalysis));
            }
        }
        private void myFunc()
        {
            x = r.Next() % 5;
            TextBlock_question.Text = questions[x];
            textbox_answer.Text = "";
            
        }
    }
}
